//
//  qiyexqViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/28.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "canpinxinxi.h"
#import "gongsijianjie.h"
#import "qiyexqViewController.h"
#import "gongsizhuye.h"
@interface qiyexqViewController ()

@end

@implementation qiyexqViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
 self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
 self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
 self.view.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
     self.navigationItem.titleView = self.searchBar;
[self requestdata];

}
#pragma mark: getter method EVNCustomSearchBar
- (EVNCustomSearchBar *)searchBar
{
    if (!_searchBar)
    {
        _searchBar = [[EVNCustomSearchBar alloc] initWithFrame:CGRectMake(0, kStatusBarHeight, KScreenWidth, 30)];
//0a62ea
        _searchBar.backgroundColor = [UIColor clearColor]; // 清空searchBar的背景色
                _searchBar.textFieldColor = [UIColor colorWithHexString:@"fbf2f2"alpha:.32];
                _searchBar.textColor = [UIColor whiteColor];
    [_searchBar.cancelButton setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
//        _searchBar.iconImage = [UIImage imageNamed:@"EVNCustomSearchBar.bundle/searchImageBlue.png"];
    _searchBar.iconImage = [UIImage imageNamed:@"search"];

        _searchBar.iconAlign = EVNCustomSearchBarIconAlignCenter;
        [_searchBar setPlaceholder:NSLocalizedString(@"请输入关键字", nil)];  // 搜索框的占位符
        _searchBar.placeholderColor = [UIColor whiteColor];
        _searchBar.delegate = self; // 设置代理
        [_searchBar.textField.layer setMasksToBounds:YES];

[_searchBar.textField.layer setCornerRadius:15];//设置矩形四个圆角半径

        [_searchBar sizeToFit];
    }
    return _searchBar;
}
- (void)searchBarTextDidEndEditing:(EVNCustomSearchBar *)searchBar{
if (searchBar.text.length>0){
NSLog(@"%@",searchBar.text);
canpinxinxi*mainview = [[canpinxinxi alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, KScreenHeight-kTopHeight-30-50)];
mainview.backgroundColor = [UIColor whiteColor];
mainview.tag = 10;
mainview.type = _type;
mainview.searchstring = searchBar.text;
mainview.string = _pdid;

[self.view addSubview:mainview];
}
}
- (void)requestdata{
 [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    NSMutableDictionary *dics=[NSMutableDictionary dictionary];
      dics[@"userName"] = @"administrator";
    dics[@"password"] = @"b628e2c3b78ef9bf269c489b35176e48";
    
    dics[@"language"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
     dics[@"website"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
        dics[@"type"] = BAtype;
  dics[@"cpid"] = _pdid;
//  dics[@"pageNumber"] = @"1";
//  dics[@"pageSize"] = @"20";
  if ([_type isEqualToString:@"caigou"]) {
      dics[@"cpstatus"] = @"1";

}else{
  dics[@"cpstatus"] = @"0";
  }
  NSString *dicstring = [httpTool dictionaryToJson:dics];
dicstring= [dicstring URLEncodedString];
NSString *url = [[NSString alloc]initWithFormat:@"%@/api/company/yellowpage?data=%@",BAip,dicstring];
 [httpTool ZBPostNetDataWith:url withDic:nil andSuccess:^(NSDictionary* dictionary){
   [MBProgressHUD hideHUDForView:self.view animated:YES];
_dic =  dictionary;
 NSLog(@"%@",dictionary);
 _comdic = dictionary[@"company"];
 [self initview];
  }andFailure:^{
  [MBProgressHUD hideHUDForView:self.view animated:YES];

//         [self.tableView headerEndRefreshing];

 }];

}
- (void)initview{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
view.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];
[self.view addSubview:view];
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
if (![_comdic[@"logoImage"]isEqual:[NSNull null]]) {
[image sd_setImageWithURL:[NSURL URLWithString:_comdic[@"logoImage"]] placeholderImage:[UIImage imageNamed:@"加载"]];
        image.layer.masksToBounds=YES;
        image.layer.cornerRadius=15.0;
    [self.view addSubview:image];

}else{
image.frame =CGRectMake(10, 10, 0, 0);
}
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(image.right+10, 10, 150, 15)];
label.font = [UIFont systemFontOfSize:12];
label.textColor = [UIColor whiteColor];
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(image.right+10, label.bottom, 150, 15)];
label1.font = [UIFont systemFontOfSize:11];
label1.textColor = [UIColor whiteColor];
label.text = _comdic[@"name"];
label1.text = _comdic[@"areaId"];
[view addSubview:label];
[view addSubview:label1];
UIButton *huiyuanbutton = [UIButton buttonWithType:UIButtonTypeCustom];
huiyuanbutton.backgroundColor = [UIColor clearColor];
[huiyuanbutton setImage:[UIImage imageNamed:@"会员企业-白色"] forState:UIControlStateNormal];
huiyuanbutton.titleLabel.numberOfLines = 0;
[huiyuanbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
huiyuanbutton.frame  = CGRectMake(KScreenWidth-110, 10, 100, 30);
    huiyuanbutton.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    huiyuanbutton.userInteractionEnabled=NO;
[view addSubview:huiyuanbutton];
UIButton *qiyebutton = [UIButton buttonWithType:UIButtonTypeCustom];
qiyebutton.backgroundColor = [UIColor clearColor];
[qiyebutton setImage:[UIImage imageNamed:@"认证企业-白色"] forState:UIControlStateNormal];
qiyebutton.titleLabel.numberOfLines = 0;

[qiyebutton setTitle:NSLocalizedString(@"商品详情-认证企业", nil) forState:(UIControlState)UIControlStateNormal];
[qiyebutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
qiyebutton.frame  = CGRectMake(KScreenWidth-210, 10, 100, 30);
    qiyebutton.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    qiyebutton.userInteractionEnabled=NO;
[view addSubview:qiyebutton];
if([_comdic[@"rztype"]isEqual:[NSNull null]]){

qiyebutton.hidden = YES;
}
if([_comdic[@"viptype"]isEqual:[NSNull null]]){

huiyuanbutton.hidden = YES;
}else{
[huiyuanbutton setTitle:_comdic[@"viptype"] forState:(UIControlState)UIControlStateNormal];


}

NSArray *array = @[NSLocalizedString(@"公司主页", nil),NSLocalizedString(@"公司简介", nil),NSLocalizedString(@"产品信息", nil)];
for (int i= 0; i<3;i++) {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = 200+i;
    button.frame = CGRectMake(i*(KScreenWidth/3), view.bottom, KScreenWidth/3,30);
   [button setTitle:array[i] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithHexString:@"a1a1a1"]forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@-默认",array[i]]] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithHexString:@"0a62ea"]forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@-选中",array[i]]] forState:UIControlStateSelected];
        button.titleLabel.font = [UIFont systemFontOfSize: 13.0];
if (i == 0) {
    button.selected = YES;
    _selectbutton = button;
}
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor whiteColor];
[self.view addSubview:button];
}
UIView *bomview = [[UIView alloc]initWithFrame:CGRectMake(0, view.bottom+29, KScreenWidth, 1)];
bomview.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
[self.view addSubview:bomview];
gongsizhuye*mainview = [[gongsizhuye alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, KScreenHeight-kTopHeight-30-50)];
mainview.backgroundColor = [UIColor whiteColor];
mainview.tag = 10;
mainview.dic = _dic;
mainview.type = _type;

[self.view addSubview:mainview];
}
- (void)action:(UIButton *)button{
button.selected = !button.selected;
if (button ==_selectbutton){
button.selected = YES;

}else{
button.selected = YES;
_selectbutton.selected = NO;

}
_selectbutton = button;
for (UIView *view in self.view.subviews) {
    if (view.tag ==10) {
    [view removeFromSuperview];
    
}
//NSLog(@"%lu",(unsigned long)self.view.subviews.count);
}
if (button.tag ==200) {
    gongsizhuye*mainview = [[gongsizhuye alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, KScreenHeight-kTopHeight-30-50)];
mainview.backgroundColor = [UIColor whiteColor];
mainview.tag = 10;
mainview.dic = _dic;
mainview.type = _type;

[self.view addSubview:mainview];
}else if (button.tag ==201){
gongsijianjie*mainview = [[gongsijianjie alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, KScreenHeight-kTopHeight-30-50)];
mainview.backgroundColor = [UIColor whiteColor];
mainview.tag = 10;
mainview.dic = _dic;
[self.view addSubview:mainview];
}else if (button.tag ==202){
canpinxinxi*mainview = [[canpinxinxi alloc]initWithFrame:CGRectMake(0, 80, KScreenWidth, KScreenHeight-kTopHeight-30-50)];
mainview.backgroundColor = [UIColor whiteColor];
mainview.tag = 10;
mainview.string = _pdid;
mainview.type = _type;
[self.view addSubview:mainview];
}

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
